#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <string.h>

//The opencv stuff
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"


//The class for Db operations 
using namespace std;

//We may need that one later dunnow
class ImageOpt{

    public :
        int id;
        char person_name[80];
        int part;
};

class DbOperation{

    public:
        bool moveFile(char *source_dir,char *dest_dir,char *source_file,char *dest_file,int type);
        bool parseImageName(string filename,ImageOpt*);
        bool removeImage(char *image_name, char *dir_name);
        bool removePerson(char* person_name,char* dir_name);
        bool addAllDir(char* dir_name,char* person_name,char* from_dir);
        int listImages(string dir_name,vector<string> &file_list); //list the images that are in directory
        bool addImage(char *image_name,char *dir_name,char *person_name,char* src_dir);
        int  printImages(string dir_name);
        bool checkIntegrity(char *dir_name); //check if something changed there
        bool recreateCache(char *dir_name); //Compute all the stuff and recreate again


      };

//**********************************************************************************************************

class EigenLearn{

    public:
        //
        EigenLearn();
        bool learn(char*); // that one recomputes again all the stuff
        virtual ~EigenLearn();

    protected:
        bool doPca(); // the pca computing
        bool loadFaceImgArray(char*);
        bool storeTrainigSet(char*,char*);
        // bool loadTrainigSet(char *xmlfile);
        
        //some vars we need in that class
        int trainFaces;
        int eigens;
        
        IplImage ** faceImages; // an array of face images
        CvMat * personMat; // an array of person matrises
        IplImage * avgTrainImg; // The avarage image that is created
        IplImage ** eigenVector; // the eigen vectors created
        CvMat * eigenValMatr;
        CvMat * projectedTrainMat;


};

//*********************************************************************************************************

//It inherits from the upper because we use almost the same funcs
class EigenTest:EigenLearn{

   public:
        bool recognize(char *test_dir,char *learn_dir);
        bool loadTrainigSet(const char *xmlfile,char *dirname);
        // the comparison place here
        int findClosestImage(int comparison_type);
        ~EigenTest();

    private:
        //that one is different from previous one
        CvMat * pTrainPersonMat;
        //that is the value we computed from projecting the test images
        float *projectedTestFace;


};
